<!-- 批量注册设备 -->
<template lang="html">
  <div class="batch-add">
    <Modal v-model="show"  :loading="modal.loading" :title="modal.title" width="700px"
           :mask-closable="false" :on-visible-change="onVisibleChange"
           :footer-hide=true >

      <Form ref="formBatchAdd" :model="batchData" label-position="right" :label-width="140" >
        <FormItem label="行政区划代码">
          <div class="select-input ivu-select ivu-select-single ivu-select-default">
            <Treeselect :options="cityCodes"
                        :multiple="false"
                        v-model="batchData.cityId"
                        noChildrenText="最后一级了"
                        :placeholder="placeholder"
                        @select="onSelect"
                        @deselect="onDeselect"></Treeselect>
          </div>
          <Input class="select-code" v-model="batchData.cityId" placeholder="行政区划代码" ></Input>
        </FormItem>
        <FormItem label="行业编码">
          <Select class="select-input" filterable :loading="loading1" v-model="codeRule.businessId" @on-change="onBusChange()">
            <Option v-for="(item, id) in businessCodes" :value="item.id" :key="id">{{item.busName}}</Option>
          </Select>
          <Input class="select-code" v-model="batchData.businessId" placeholder="行业编码" ></Input>
        </FormItem>
        <FormItem label="设备类型编码">
          <Select class="select-input" filterable :loading="loading2" v-model="codeRule.deviceTypeId">
            <Option v-for="(item, id) in deviceCodeType" :value="item.id" :key="id">{{item.codeTypeName}}</Option>
          </Select>
          <Input class="select-code" v-model="batchData.deviceTypeId" placeholder="设备类型编码" ></Input>
        </FormItem>
        <FormItem label="网络标识">
          <Select class="select-input" filterable :loading="loading2" v-model="codeRule.netIdentityId">
            <Option v-for="(item, id) in codeNetIdentity" :value="item.id" :key="id">{{item.netIdentityName}}</Option>
          </Select>
          <Input class="select-code" v-model="batchData.netIdentityId" placeholder="网络标识" ></Input>
        </FormItem>
        <FormItem label="注册数量">
          <InputNumber v-model="loop.start" :min="0" :max="50" size="small" style="width: 100px;"></InputNumber>
        </FormItem>
      </Form>
    </Modal>
  </div>
</template>
<script>
import CodeRule from "@/api/CodeRule";
import {apiResult} from "@/libs/util";

export default {
  name: "Device4gBatchAdd",
  data() {
    return {
      show:false,
      api: new CodeRule(),
      loading1:false,
      loading2:false,
      batchData:{
        cityId:null,
        businessId:null,
        deviceTypeId:null,
        netIdentityId:null,
        num:0,
      },
      cityCodes:[],
      businessCodes:[],
      centerCodeType:[],
      deviceCodeType:[],
      codeNetIdentity:[]
    }
  },
  methods:{
    openDialog(action,row, callback) {
      this.show=true;
    }
  },
  mounted() {
    this.api.findCodeCity().then(res=>{
      this.testCity=[];
      apiResult(res.data,false,result=>{
        for(let i in result.data){
          const parent ={
            label:result.data[i].label,
            id:result.data[i].value,
            children:[]
          }
          this.testCity.push(parent);
          if (!! result.data[i].children){
            for(let j in result.data[i].children){
              this.genChildren(parent,result.data[i].children[j])
            }
          }
        }
        //console.log(this.testCity);
        //this.cityCodes=[];
        this.cityCodes=this.testCity;//res.data.data;
      })

    })
      this.api.findCodeBusiness().then(res=>{
        this.businessCodes=[];
        apiResult(res.data,false,result=>{
          this.businessCodes=result.data;
        })

      })
    this.api.findCodeType().then(res=>{
      this.centerCodeType=[];
      this.deviceCodeType=[];
      apiResult(res.data,false,result=>{
        this.centerCodeType=result.data;
        this.deviceCodeType=this.centerCodeType;
      })

    })

    this.api.findCodeNetIdentity().then(res=>{
      this.codeNetIdentity=[];
      apiResult(res.data,false,result=>{
        this.codeNetIdentity=result.data;
      });
    })
  }
}
</script>
<style lang="css">
.batch-add {
  text-align: left;
  padding: 10px;
  background: #fff;
  border: 1px solid #dcdfe6;
  box-shadow: 0 2px 4px 0 rgba(0,0,0,.12), 0 0 6px 0 rgba(0,0,0,.04);
}

</style>
